<?php
/**
 * Created by PhpStorm.
 * User: chenzhitao
 * Date: 2018/4/18
 * Time: 上午11:30
 */

namespace App\Busi\Modules\Auth;


use App\Busi\Modules\BaseBusi;
use App\Busi\Traits\UserTrait;
use App\Exceptions\ErrorCode\UserError;
use App\Exceptions\UserException;
use App\Http\Requests\AuthLoginRo;
use App\Models\User;

class LoginBusi extends BaseBusi
{
    use UserTrait;
    public function handle(AuthLoginRo $ro){
        $user = User::where('phone',$ro->phone)->first();
        if(!$user){
            UserException::touch(UserError::USER_NOT_EXIST);
        }
        if(md5($ro->password) !=  $user['password']){
            UserException::touch(UserError::PASSWORD_ERROR);
        }

        $data = array(
            'uid'=>$user['uid'],
            'name' => $user['name'],
            'phone' => $user['phone'],
            'avatar' => $user['avatar'],


        );
        $this->setUserLoginStatus($user['uid'],$user['phone']);
        return $data;
    }

}